//#condition (JarFile||PimFile)&&MicroLogos||RmsFile
//# package MicroLogos;
//# 
//# //TODO: zde by PimFile nemuselo byt, jen z testovacich duvodu
//# 
//# /*
//#  * rmsFile.java
//#  *
//#  * Created on 2. �nor 2007, 17:45
//#  *
//#  * To change this template, choose Tools | Template Manager
//#  * and open the template in the editor.
//#  */
//# 
//# import javax.microedition.rms.*;
//# import java.io.*;
//# 
//# /**
//#  *
//#  * @author Marek
//#  */
//# public class RmsFile extends com.siemens.mp.io.File {
//# ////#ifndef MicroLogos
//#   public static final String VENDOR="Marek Krcal";
//#   public static final String SUITE=/*"mVocabSL45";*/"MicroLogos";
//# ////#endif
//#   public static int NUM_HANDLES=10;
//#   public static int READ=0;
//#   public static int WRITE=1;
//#   public static int READ_WRITE=2;
//#   public static int BLOCK_SIZE=4096*4;
//#   
//#   public static final int SIZE=1;
//#   public static final int BEGIN=1;
//#   public int storeLimit=0;
//#   String[] fileConnections;
//#  int []pozitions;
//#  int []sizes;
//# 
//#  byte[][] buffers;
//#  RecordStore[][] recordStores;  
//#  RecordStore[] sizeStores;
//#   /** Creates a new instance of rmsFile */
//#   public RmsFile(){
//#     try {
//#         RecordStore store = RecordStore.openRecordStore("MyStore", true);
//#         storeLimit=store.getSizeAvailable();
//#         storeLimit=(storeLimit/BLOCK_SIZE-1)*BLOCK_SIZE;
//#         System.out.println("storeLimit: "+storeLimit);
//#         store.closeRecordStore();
//#     } catch (Exception e) {
//#         System.out.println("RmsFile: nedetekoval jsem storeLimit, je to v haji:"+e.getMessage());
//#         e.printStackTrace();
//#     }
//#     fileConnections=new String[NUM_HANDLES];
//#     pozitions=new int[NUM_HANDLES];
//#     sizes=new int[NUM_HANDLES];
//#     buffers=new byte[NUM_HANDLES][];
//#     recordStores=new RecordStore[NUM_HANDLES][];
//#     sizeStores=new RecordStore[NUM_HANDLES];
//# //    firstSeeks=new int[NUM_HANDLES];
//#     for (int i=0;i<NUM_HANDLES;i++) {buffers[i]=null;}
//#     
//#   }
//#  public int open(String fileName,int mode) throws IOException{
//#    return open(fileName);
//#  }
//#  
//#  public int open(String fileName) throws IOException{
//#    int i=0;
//#    for (i=0;i<NUM_HANDLES;i++) if (fileConnections[i]==null) break;
//#    if (i==NUM_HANDLES) {return -1;}
//# //     FileConnection fc=(FileConnection)Connector.open(fileName,Connector.READ_WRITE);
//#    fileConnections[i]=fileName;
//#    buffers[i]=null;
//#    try{
//# ////#ifdef MicroLogos
//# ////#else
//# System.out.println("Prvni metoda rms: "+fileName);
//#      try{
//#        sizeStores[i]=RecordStore.openRecordStore(fileName,VENDOR,SUITE);
//#      }catch(Exception e){}
//#      if (sizeStores[i]==null) try{
//# System.out.println("Druha metoda rms");
//#     sizeStores[i]=RecordStore.openRecordStore(fileName,fileName,fileName);
//#      }catch(Exception e){}
//#      if (sizeStores[i]==null) try{
//# System.out.println("Treti metoda rms");
//#        sizeStores[i]=RecordStore.openRecordStore(fileName,"Marek Krcal","mVocabSL45");
//#      }catch(Exception e){}
//#      if (sizeStores[i]==null) {
//# System.out.println("Ctvrta metoda rms");
//#         sizeStores[i]=RecordStore.openRecordStore(fileName,true,RecordStore.AUTHMODE_ANY,true);
//#      }
//# //TODO:nechapu proc znovu
//# if (sizeStores[i]==null) {System.out.println("Prvni metoda rms: "+fileName);
//#      try{
//#        sizeStores[i]=RecordStore.openRecordStore(fileName,VENDOR,SUITE);
//#      }catch(Exception e){}
//#      if (sizeStores[i]==null) try{
//# System.out.println("Druha metoda rms");
//#     sizeStores[i]=RecordStore.openRecordStore(fileName,fileName,fileName);
//#      }catch(Exception e){}
//#      if (sizeStores[i]==null) try{
//# System.out.println("Treti metoda rms");
//#        sizeStores[i]=RecordStore.openRecordStore(fileName,"Marek Krcal","mVocabSL45");
//#      }catch(Exception e){}
//#      if (sizeStores[i]==null) {
//# System.out.println("Ctvrta metoda rms");
//#         sizeStores[i]=RecordStore.openRecordStore(fileName,true,
//#                 RecordStore.AUTHMODE_ANY,true);
//#      }
//# if (sizeStores[i]==null) System.out.println("Nic nepomohlo");
//# }
//# ////#endif
//#      if (sizeStores[i].getNumRecords()<1) {
//#        sizes[i]=0;
//#        writeSize(i);
//#      }else{
//#        byte[]b=sizeStores[i].getRecord(1);
//#        sizes[i]=((b[0]&0xff)|((b[1]&0xff)<<8)|((b[2]&0xff)<<16)|(b[3]&0xff)<<24);
//#      }
//#      if (recordStores[i]==null) recordStores[i]=new RecordStore[sizes[i]/storeLimit+1];           
//#      int j=0;
//#      for (j=0;j<recordStores[i].length;j++) recordStores[i][j]=RecordStore.openRecordStore(
//#             fileName+j,true,RecordStore.AUTHMODE_ANY,true);
//#    }catch(Exception e){throw new IOException("open: "+e.toString());}
//#    pozitions[i]=Integer.MAX_VALUE;//ani neni potreba
//#    return i;
//#  }
//#  public int length(int fd){
//# if (fileConnections[fd]==null) {System.out.println("Nemelo by se stat: fd neni open");return 0;}
//# if (fd<0||fd>=NUM_HANDLES) {System.out.println("Nemelo by se stat: fd ven z mezi");return 0;}   
//#    return sizes[fd];
//#  }
//#  private void writeSize(int fd) throws IOException{
//#    byte[]b=new byte[4];
//#    int size=sizes[fd];
//#    b[0]=(byte)(size&0xff);
//#    b[1]=(byte)((size>>8)&0xff);
//#    b[2]=(byte)((size>>16)&0xff);
//#    b[3]=(byte)((size>>24)&0xff);
//#    try{
//#      if (sizeStores[fd].getNumRecords()==0){
//#        sizeStores[fd].addRecord(b,0,4);
//#      }else {
//#        sizeStores[fd].setRecord(1,b,0,4);
//#      }
//#    }catch(Exception e){throw new IOException("JarFile.writeSize: "+e.toString());}
//#  }
//#  private void writeBuffer(int fd) throws Exception{
//#    this.recordStores[fd][pozitions[fd]/storeLimit].setRecord((pozitions[fd]%storeLimit)/
//#        BLOCK_SIZE+BEGIN,buffers[fd],0,BLOCK_SIZE);
//#  }
//#  public int write(int fd,byte[]buf, int offset, int numBytes)throws IOException{
//# if (fd<0||fd>=NUM_HANDLES) {System.out.println("Nemelo by se stat: fd ven z mezi");return 0;}
//# if (offset<0||offset+numBytes>buf.length) {System.out.println("Nemelo by se stat: offset ven z mezi bufu "+offset+" "+numBytes);return 0;}
//#    if (buffers[fd]==null) seek(fd,0);
//#    if (buffers[fd]==null) return -1;
//# //System.out.println("ve write: zapisuji bytu:"+numBytes);
//# //   try{
//#    int wrote=0;
//#    int wroteOnce;
//#    String fc=fileConnections[fd];
//#    try {do{
//#      int poz=pozitions[fd]%BLOCK_SIZE;
//#      System.arraycopy(buf,offset,buffers[fd],poz,
//#              wroteOnce=Math.min(BLOCK_SIZE-poz,numBytes));
//#      this.writeBuffer(fd);
//#      wrote+=wroteOnce;
//#      offset+=wroteOnce;
//#      numBytes-=wroteOnce;
//#      if (pozitions[fd]+wroteOnce>sizes[fd]) {
//# //System.out.println("Zvetsuji velikost: "+sizes[fd]+"->"+(pozitions[fd]+wroteOnce));
//#        sizes[fd]=pozitions[fd]+wroteOnce;
//#        writeSize(fd);
//#      }
//#      if ((pozitions[fd]+wroteOnce)%BLOCK_SIZE==0) //calling only the seek would be enough
//#        seek(fd,pozitions[fd]+wroteOnce);          //"if" is for higher speed
//#      else pozitions[fd]+=wroteOnce;
//#    }while (wroteOnce>0&&numBytes>0);
//#    }catch(Exception e){throw new IOException("write: "+e.toString());}
//#    return wrote;
//#  }
//#  private int min(int a,int b,int c){
//#    if (a<=b&&a<=c) return a;
//#    if (b<=a&&b<=c) return b;
//#    return c;
//#  }
//#   
//#  public int read(int fd, byte[] buf, int offset, int numBytes)throws IOException{
//# if (fd<0||fd>=NUM_HANDLES) {System.out.println("Nemelo by se stat: fd ven z mezi");return 0;}
//# if (offset<0||offset+numBytes>buf.length) {System.out.println("Nemelo by se stat: offset ven z mezi bufu "+offset+" "+numBytes);return 0;}
//# //System.out.println("Pred event. seek");
//#    if (buffers[fd]==null) seek(fd,0);
//#    if (buffers[fd]==null) return -1;
//# //System.out.println("Po event. seek");
//# //   try{
//#    int read=0;
//#    int readOnce;
//#    String fc=fileConnections[fd];
//#    do{
//#      int poz=pozitions[fd]%BLOCK_SIZE;
//#      System.arraycopy(buffers[fd],poz,buf,offset,
//#              readOnce=min(BLOCK_SIZE-poz,numBytes,sizes[fd]-pozitions[fd]));
//#      read+=readOnce;
//#      offset+=readOnce;
//#      numBytes-=readOnce;
//#      if ((pozitions[fd]+readOnce)%BLOCK_SIZE==0) //calling only the seek would be enough
//#        seek(fd,pozitions[fd]+readOnce);         //"if" is for higher speed
//#      else pozitions[fd]+=readOnce;
//#    }while (readOnce>0&&numBytes>0&&pozitions[fd]<sizes[fd]);
//#    return read;
//# //   }catch (IOException e) {return -1;}
//#  }
//#  public int seek(int fd, int seekpos)throws IOException{
//# //System.out.println("zac seek");
//# //   String fc=fileConnections[fd];
//# //   if (fc==null)throw new IOException("seek: filename je null");
//#    if (seekpos>sizes[fd]) throw new IOException("seek: seekpoz je vetsi nez velikost");
//# //   try{
//#    try{
//#      if ((seekpos/BLOCK_SIZE!=pozitions[fd]/BLOCK_SIZE)){
//# //System.out.println("Menim blok: "+(seekpos/BLOCK_SIZE));
//#        if (buffers[fd]!=null){//Pocita se s tim, ze zapis bufferu se provede pri kazdym write
//# //         writeBuffer(fd);
//#        }else buffers[fd]=new byte[BLOCK_SIZE];
//#        if (seekpos/storeLimit==recordStores[fd].length){
//# //System.out.println("seek: zvetsuju recordStores na"+(recordStores[fd].length*2));
//#          RecordStore pomStores[]=new RecordStore[recordStores[fd].length*2];
//#          System.arraycopy(recordStores[fd],0,pomStores,0,recordStores[fd].length);
//#          recordStores[fd]=pomStores;
//#        }
//#        if (recordStores[fd][seekpos/storeLimit]==null){
//# //System.out.println("seek: pridavam novou polozku do recordStores");
//#          recordStores[fd][seekpos/storeLimit]=RecordStore.openRecordStore(
//#              fileConnections[fd]+(seekpos/storeLimit),true,RecordStore.AUTHMODE_ANY,true);
//#        }
//#        if (recordStores[fd][seekpos/storeLimit].getNumRecords()<
//#                (seekpos%storeLimit)/BLOCK_SIZE+BEGIN){
//# //System.out.println("seek: I am adding a record");
//#          recordStores[fd][seekpos/storeLimit].addRecord(buffers[fd],0,BLOCK_SIZE);
//#        }else {
//# //System.out.println("seek: I am getting a record");
//#          int pom=0;
//#          if ((pom=recordStores[fd][seekpos/storeLimit].
//#              getRecord((seekpos%storeLimit)/BLOCK_SIZE+BEGIN,buffers[fd],0))
//#           !=BLOCK_SIZE){
//#            System.out.println("velikost recordu: "+pom);        
//#            throw new IOException("nemelo by se stat: blok nebyl v RMS dost velkej."+
//#                "Try deleting old RMS files and create new ones with proper BLOCK_SIZE."); 
//#          }
//#        }
//#      }
//#    }catch(Exception e){throw new IOException("IO-seek: "+e.toString());}
//# //System.out.println("po skip");
//#    pozitions[fd]=seekpos;
//#    return seekpos;
//# //   }catch (IOException e) {return -1;}
//#  }
//# 
//#  public int close(int fd) throws IOException{
//#    if (fileConnections[fd]==null)return -1;
//# //   int ret=1;
//#    try{
//#      fileConnections[fd]=null;
//# //     if (buffers[fd]!=null)writeBuffer(fd);
//#      buffers[fd]=null;
//#      sizeStores[fd].closeRecordStore();
//#      for (int i=0;i<recordStores.length;i++)
//#        if (recordStores[i]!=null) for(int j=0;j<recordStores[i].length;j++)
//#          if (recordStores[i][j]!=null) recordStores[i][j].closeRecordStore();
//#    }catch(Exception e){throw new IOException("IO-close: "+e.toString());}
//#    return 1;
//#  }
//#  
//#  public int existsNonStatic(String fileName){
//#    try{
//#ifdef MicroLogos
//#      RecordStore recordStore=RecordStore.openRecordStore(fileName,false);
//#else
//#   RecordStore recordStore=RecordStore.openRecordStore(fileName,VENDOR,SUITE);
//#endif
//#      if (recordStore!=null){
//#        recordStore.closeRecordStore();
//#        return 1;
//#      }
//#    }catch(Exception e){}
//#    return -1;
//#  }
//# /* private boolean isRms(int fd){
//#    return isRms(fileConnections[fd]);
//#  }
//#  private static boolean isRms(String filename){
//#    return (filename.charAt(0)!='/');
//#  }*/  
//# }
//# 